package com.ruoyi.web.controller.system;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.TreeSelect;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/system/params")
public class SysUtilController extends BaseController {
    @Autowired
    private ISysRoleService roleService;
    @Autowired
    private ISysPostService postService;
    @Autowired
    private ISysDeptService deptService;

    @GetMapping("getAllParams")
    public AjaxResult getAllParams() {
        Map result = new HashMap();
        ArrayList roleValueList = new ArrayList();
        ArrayList<SysRole> roleList = (ArrayList<SysRole>) roleService.selectRoleAll();
        for(SysRole sr:roleList){
            Map rv = new HashMap();
            rv.put("value",sr.getRoleId());
            rv.put("text",sr.getRoleName());
            roleValueList.add(rv);
        }
        ArrayList<SysPost>postList = (ArrayList<SysPost>) postService.selectPostAll();
        ArrayList postValueList = new ArrayList();
        for(SysPost sp:postList){
            Map sv = new HashMap();
            sv.put("value",sp.getPostId());
            sv.put("text",sp.getPostName());
            postValueList.add(sv);
        }
        result.put("roleSource",roleValueList);
        result.put("postSource",postValueList);
        SysDept dept = new SysDept();
        List<SysDept> depts = deptService.selectDeptList(dept);
        List<TreeSelect> deptTree= deptService.buildDeptTreeSelect(depts);
        result.put("departTreeSource",deptTree);
        return AjaxResult.success(result);
    }
}
